<?php
/**
 * du 2024.10.12
 * 节目试玩版页面控制器
 */
namespace Home\Controller;
use Think\Controller;

class TrialController extends Controller{
    public function __construct(){
        parent::__construct();
        $this->title = '奔跑吧R星人';
    }
    public function index(){
        $id = I('param.id');
        // D('TvGameClueAdmin')->set_data(['id' => $id, 'status' => 'index']);
        $user = D('TvGameClueAdmin')->get_data($id);
        $this->assign('user',$user);
        $this->display('index');

    }

    public function next(){
        $id = I('param.id');
        D('TvGameClueAdmin')->set_data(['id' => $id, 'status' => 'next']);
        $this->display();
    }

    public function admin(){
        $user = D('TvGameClueAdmin')->get_data_list();
        $clue = D('TvGameClue')->get_clue_list();
        $this->assign('user',$user);
        $this->assign('clue',$clue);
        $this->assign('max', $clue[count($clue) - 1]['id']);
        $this->display();
    }

    public function set_data(){
        $data = I('param.');
        $res = D('TvGameClueAdmin')->set_data($data);
        _apiReturn(1,'线索已发放', $res);
    }

    public function get_data(){
        $id = I('param.id');
        $data = D('TvGameClueAdmin')->get_data($id);
        if($data['status'] == 'clue'){
            $data['clue'] = D('TvGameClue')->get_clue($data['clue']); 
        }
        _apiReturn(1,'获取成功', $data);
    }

    public function clue(){
        $id = I('param.id');
        $user = D('TvGameClueAdmin')->get_data($id);
        $clue = D('TvGameClue')->get_clue($user['clue']);
        $this->assign('clue',$clue);
        $this->display();
    }

    public function game(){
        $id = I('param.id');
        $user = D('TvGameClueAdmin')->get_data($id);
        $data = ['id' => $id];
        if($user['game'] == 3){
            $data['image'] = $user['image'] + 1;
        }
        if($user['status'] == 'next'){
            $data['status'] = 'game';
        }
        D('TvGameClueAdmin')->set_data($data);
        $this->display('game' . $user['game']);
    }

    function get_clue(){
        $id = I('param.id');
        $user = D('TvGameClueAdmin')->get_data($id);
        if($user['status'] == 'clue'){
            $user['clue'] = D('TvGameClue')->get_clue($user['clue']);
        }
        _apiReturn(1,'获取成功', $user);
    }

    public function get_data_list(){
        $list = D('TvGameClueAdmin')->get_data_list();
        _apiReturn(1,'获取成功', $list);
    }

    public function set_game_success(){
        $id = I('id');
        $res = D('TvGameClueAdmin')->set_data(['id' => $id,'status' => 'win']);
        _apiReturn(1,'修改成功', $res);
    }

    public function add_clue(){
        $data = I('param.');
        $data['type'] = 'text';
        $res = M('TvGameClue')->data($data)->add();
        _apiReturn(1,'添加成功', $res);
    }

    public function checkbox(){
        $list = range(1,100);
        $this->assign('list',$list);
        $this->display();
    }

    public function diff(){
        $user = D('TvGameClueAdmin')->get_data(I('id'));
        $page = $user['image'] % 4 + 1;
        $image_list = D('TvGameImage')->get_image_list($page);
        $this->assign('image_list',$image_list);
        $this->display();
    }
}